//###############
//FILE : FileContainFileSession.java
//WRITER : Daniel Lowengrub, daniel_i_l, 320687098
//EXERCISE : oop ex3 2011
//DESCRIPTION:
//See below
//###############

package oop.ex3.protocol.sessions;

import oop.ex3.protocol.messages.ContainFileMsg;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import oop.ex3.exceptions.InvalidMessageException;

/**
 * Notify a NS that this FS contains a certain file.
 * @author daniel
 */
public class FileContainFileSession extends FileToNameSession {
    private String _fileName;

    /**
     * Create a new session.
     */
    public FileContainFileSession() {
        super();
    }

    /**
     * Set the file name we want to send.
     * @param fileName The file name.
     */
    public void setFileName(String fileName) {
        _fileName = fileName;
    }

    @Override
    protected boolean specExecuteSession(DataInputStream inputStream, DataOutputStream outputStream) throws IOException, InvalidMessageException {
        if (!initSession(inputStream, outputStream))
            return false;

        ContainFileMsg containFile = new ContainFileMsg();
        containFile.setFileName(_fileName);
        containFile.send(outputStream);

        _done.receive(inputStream);

        if (!endSession(inputStream, outputStream))
            return false;

        return true;
    }

}
